﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace server_logic_simulator
{
    public class Skill
    {
        public int mID;
        public string mName;
        public Career mCareerLimit;
        public int mCooldownRound;
        public TargetSelectMode mTargetSelectMode;
        public string mDescription;
        // Target select mode
        public enum TargetSelectMode
        {
            MeleeMode = 0,      // prefer front row enemy
            RangeMode = 1,      // random select enemy
            AssassinMode = 2,   // prefer back row enemy
            AllianceMode = 3    // alliance
        };

        // TEST function 
        public static Skill GetTestSkill()
        {
            Skill ret_skill = new Skill();

            ret_skill.mID = 0;
            ret_skill.mName = "Test Skill";
            ret_skill.mTargetSelectMode = TargetSelectMode.MeleeMode;
            ret_skill.mCooldownRound = 0;
            ret_skill.mDescription = "A basic but powerful attack... Kill U !!!";

            return ret_skill;
        }

        public List<Character> SelectTargets(Skill skill, Team affected_team)
        {
            List<Character> target_list = new List<Character>();

            // TODO: replace the random logic with real one
            int idx = Utils.Random(0, affected_team.mCharacterInBattleList.Count); ;
            Team.CharacterInBattle character_inBattle = affected_team.mCharacterInBattleList[idx] as Team.CharacterInBattle;

            // Add target to the list
            target_list.Add(character_inBattle.mCharacter);

            return target_list;
        }

        public int CalculateSkillDamage(Character attacker, Character target)
        {
            // TODO: replace with real logic
            int weaponDamage = Utils.Random(attacker.mWeaponDamageLL, attacker.mWeaponDamageUL + 1);
            int attack = weaponDamage + attacker.mAttack;
            int damage = attack * attack * attacker.mMight / (target.mToughness * (attack + target.mDefence));

            int weaponMagicDamage = Utils.Random(attacker.mWeaponMagicDamageLL, attacker.mWeaponMagicDamageUL + 1);
            int magicAttack = weaponMagicDamage + attacker.mMagicAttack;
            int magicDamage = magicAttack * magicAttack * attacker.mIntelligence / (target.mToughness * (magicAttack + target.mMagicDefence));

            return damage + magicDamage;
        }
    }
}
